package com.tudouji.project.copy.service.impl;

import java.math.BigDecimal;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tudouji.project.copy.mapper.CopytokdMapper;
import com.tudouji.project.copy.domain.Copytokd;
import com.tudouji.project.copy.service.ICopytokdService;

/**
 * 待同步数据Service业务层处理
 * 
 * @author wf
 * @date 2021-01-07
 */
@Service
public class CopytokdServiceImpl implements ICopytokdService 
{
    @Autowired
    private CopytokdMapper copytokdMapper;

    /**
     * 查询待同步数据
     * 
     * @param id 待同步数据ID
     * @return 待同步数据
     */
    @Override
    public Copytokd selectCopytokdById(Long id)
    {
        return copytokdMapper.selectCopytokdById(id);
    }

    /**
     * 获取最大序列号
     *
     * @param copytokd
     * @return
     */
    public Long getMaxlinkedid(Copytokd copytokd){
        return this.copytokdMapper.getMaxlinkedid(copytokd);
    }

    /**
     * 查询带同步数据表头和明细
     *
     * @param copytokd
     * @return
     */
    public List<Copytokd> selectcopytokdAllList(Copytokd copytokd){
        return copytokdMapper.selectcopytokdAllList(copytokd);
    }

    /**
     * 查询待同步数据列表
     * 
     * @param copytokd 待同步数据
     * @return 待同步数据
     */
    @Override
    public List<Copytokd> selectCopytokdList(Copytokd copytokd)
    {
        return copytokdMapper.selectCopytokdList(copytokd);
    }

    /**
     * 新增待同步数据
     * 
     * @param copytokd 待同步数据
     * @return 结果
     */
    @Override
    public int insertCopytokd(Copytokd copytokd)
    {
        return copytokdMapper.insertCopytokd(copytokd);
    }

    /**
     * 修改待同步数据
     * 
     * @param copytokd 待同步数据
     * @return 结果
     */
    @Override
    public int updateCopytokd(Copytokd copytokd)
    {
        Copytokd cp=copytokdMapper.selectCopytokdById(copytokd.getId());
//        Copytokd cpy=new Copytokd();
//        cpy.setCode(cp.getCode());
//        List<Copytokd> cps=copytokdMapper.selectCopytokdList(cpy);
//        for (Copytokd cp1 : cps) {
//            if(cp1.getIssplit()==1){
//                return 0;
//            }
//        }
        if(cp.getStatus()==6){
            return 0;
        }
        return copytokdMapper.updateCopytokd(copytokd);
    }

    /**
     * 批量删除待同步数据
     * 
     * @param ids 需要删除的待同步数据ID
     * @return 结果
     */
    @Override
    public int deleteCopytokdByIds(Long[] ids)
    {
        return copytokdMapper.deleteCopytokdByIds(ids);
    }

    /**
     * 删除待同步数据信息
     * 
     * @param id 待同步数据ID
     * @return 结果
     */
    @Override
    public int deleteCopytokdById(Long id)
    {
        return copytokdMapper.deleteCopytokdById(id);
    }

    /**
     * 根据业务编码查询数量，用于金蝶编号顺序号
     *
     * @param code
     * @return
     */
    @Override
    public Integer getSort(String code){
        return this.copytokdMapper.getSort(code);
    }

    /**
     * 更新领料单为已同步
     *
     * @param code
     * @return
     */
    @Override
    public int updatePickinglist(String code){
        return this.copytokdMapper.updatePickinglist(code);
    }

    /**
     * 采收入库获取货运单结算金额
     *
     * @param guid
     * @return
     */
    @Override
    public BigDecimal getSettlement(String guid){
        return this.copytokdMapper.getSettlement(guid);
    }
}
